package org.example.service.impl;

import com.baidu.fsg.uid.UidGenerator;
import org.example.mapper.ProjectMapper;
import org.example.service.ProjectService;
import org.example.vo.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private UidGenerator uidGenerator;

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    @Transactional
    public void batchInsertProjects(String name, int stepLength, String[] uids) {
        //List<Project> projectList = new ArrayList<>(stepLength*uids.length);
        for (int j = 0; j < uids.length; j++) {
            String uid = uids[j];
            for (int i = j*stepLength; i < (j+1)*stepLength; i++) {
                Project project = new Project();
                //project.setId(uidGenerator.getUID());
                project.setId(Long.parseUnsignedLong(""+(i+1)));
                project.setName(name + (i+1));
                project.setChargeUserId(uid);
                project.setCreateTime(new Date());
                project.setSortOrder(Double.valueOf(""+(i+1)));
                //projectList.add(project);
                projectMapper.insert(project);
            }
        }
        //projectMapper.insert(projectList, 5000);//
    }

}
